<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单ID">
          <a-input placeholder="请输入订单ID" v-decorator="['orderId', validatorRules.orderId ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单完成时间(时间戳，毫秒)">
          <a-input placeholder="请输入订单完成时间(时间戳，毫秒)" v-decorator="['finishTime', validatorRules.finishTime ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="下单设备(1:PC,2:无线)">
          <a-input placeholder="请输入下单设备(1:PC,2:无线)" v-decorator="['orderEmt', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="下单时间(时间戳，毫秒)">
          <a-input placeholder="请输入下单时间(时间戳，毫秒)" v-decorator="['orderTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="父单的订单ID，仅当发生订单拆分时返回">
          <a-input placeholder="请输入父单的订单ID，仅当发生订单拆分时返回" v-decorator="['parentId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单维度预估结算时间">
          <a-input placeholder="请输入订单维度预估结算时间" v-decorator="['payMonth', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="下单用户是否为PLUS会员 0：否，1：是">
          <a-input-number v-decorator="[ 'plus', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家ID">
          <a-input placeholder="请输入商家ID" v-decorator="['popId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单包含的商品信息列表">
          <a-input placeholder="请输入订单包含的商品信息列表" v-decorator="['skuList', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="推客的联盟ID">
          <a-input-number v-decorator="[ 'unionId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="推客生成推广链接时传入的扩展字段">
          <a-input placeholder="请输入推客生成推广链接时传入的扩展字段" v-decorator="['ext1', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单维度的有效码">
          <a-input placeholder="请输入订单维度的有效码" v-decorator="['validCode', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否还有更多,true：还有数据；false:已查询完毕">
          <a-input placeholder="请输入是否还有更多,true：还有数据；false:已查询完毕" v-decorator="['hasMore', {}]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "JD_orderModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        orderId:{rules: [{ required: true, message: '请输入订单ID!' }]},
        finishTime:{rules: [{ required: true, message: '请输入订单完成时间(时间戳，毫秒)!' }]},
        },
        url: {
          add: "/jd/jD_order/add",
          edit: "/jd/jD_order/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'orderId','finishTime','orderEmt','orderTime','parentId','payMonth','plus','popId','skuList','unionId','ext1','validCode','hasMore'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>